package cz.muni.fi.pa036is.dtoconverters;

import cz.muni.fi.pa036is.dto.PersonBasicTO;
import cz.muni.fi.pa036is.dto.PersonDetailTO;
import cz.muni.fi.pa036is.dto.PersonFormTO;
import cz.muni.fi.pa036is.dto.PersonGridTO;
import cz.muni.fi.pa036is.entity.Person;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Shebik
 */
public class PersonConverter {

    public static List<PersonBasicTO> convertToPersonBasicTOList(
            final List<Person> personList) {
        final List<PersonBasicTO> personBasicTOList = new ArrayList<PersonBasicTO>();

        for (final Person person : personList) {
            personBasicTOList.add(convertToPersonBasicTO(person));
        }
        return personBasicTOList;
    }

    private static PersonBasicTO convertToPersonBasicTO(final Person person) {
        final PersonBasicTO personBasicTO = new PersonBasicTO();
        personBasicTO.setId(person.getId());
        personBasicTO.setFirstName(person.getFirstName());
        personBasicTO.setLastName(person.getLastName());
        return personBasicTO;
    }

    private PersonConverter() {
    }

    public static Person convertToPerson(final PersonFormTO personFormTO) {
        final Person person = new Person();
        person.setId(personFormTO.getId());
        person.setFirstName(personFormTO.getFirstName());
        person.setLastName(personFormTO.getLastName());
        person.setDateOfBirth(personFormTO.getDateOfBirth());
        person.setEmail(personFormTO.getEmail());
        person.setPhoneNumber(personFormTO.getPhoneNumber());
        return person;
    }

    public static PersonFormTO convertToPersonFormTO(final Person person) {
        final PersonFormTO personFormTO = new PersonFormTO();
        personFormTO.setId(person.getId());
        personFormTO.setFirstName(person.getFirstName());
        personFormTO.setLastName(person.getLastName());
        personFormTO.setDateOfBirth(person.getDateOfBirth());
        personFormTO.setEmail(person.getEmail());
        personFormTO.setPhoneNumber(person.getPhoneNumber());
        return personFormTO;
    }
	
    public static PersonDetailTO convertToPersonDetailTO(final Person person) {
        final PersonDetailTO personDetailTO = new PersonDetailTO();
        personDetailTO.setId(person.getId());
        personDetailTO.setFirstName(person.getFirstName());
        personDetailTO.setLastName(person.getLastName());
        personDetailTO.setDateOfBirth(person.getDateOfBirth());
        personDetailTO.setEmail(person.getEmail());
        personDetailTO.setPhoneNumber(person.getPhoneNumber());
        return personDetailTO;
    }

    public static PersonGridTO convertToPersonGridTO(final Person person) {
        final PersonGridTO personGridTO = new PersonGridTO();
        personGridTO.setId(person.getId());
        personGridTO.setFirstName(person.getFirstName());
        personGridTO.setLastName(person.getLastName());
        personGridTO.setDateOfBirth(person.getDateOfBirth());
        personGridTO.setEmail(person.getEmail());
        personGridTO.setPhoneNumber(person.getPhoneNumber());
        return personGridTO;
    }
				
				public static Person convertToPerson(final PersonDetailTO personDetailTO) {
        final Person person = new Person();
        person.setId(personDetailTO.getId());
        person.setFirstName(personDetailTO.getFirstName());
        person.setLastName(personDetailTO.getLastName());
        person.setDateOfBirth(personDetailTO.getDateOfBirth());
        person.setEmail(personDetailTO.getEmail());
        person.setPhoneNumber(personDetailTO.getPhoneNumber());
        return person;
    }

    public static List<PersonGridTO> convertToPersonGridTOList(
            final List<Person> personList) {
        final List<PersonGridTO> personGridTOList = new ArrayList<PersonGridTO>();

        for (final Person person : personList) {
            personGridTOList.add(convertToPersonGridTO(person));
        }
        return personGridTOList;
    }

}
